$(function(){
	list();
})

function list(){
	var htmlList = '';
	var arr = {
		hf_s_id: 'WD11',
		hf_srv_id: 'Cv_jcus_order',
		hs_action_id: 'get_list',

		hs_sort_type: 'ORDER_NO',
		hs_sort_seq: 'DESC',
		hs_list_all_order:'Y'
	}
	getAjaxRequest(arr,function(result){
		var len = result.length;
		if(result.bs_is_login==BS_IS_LOGIN.N){
			window.location.href=MPJ.base+'/pages/login.jsp';
		}
		if( len > 0){
			for ( var i = 0; i<len; i++) {
				var type = '';
				if(result[i].bs_order_typ == 'Normal'){
					type = 'empty';
				}else if(result[i].bs_order_typ == 'PRE-ORDER'){
					type = 'Pre-order';
				}else if(result[i].bs_order_typ == 'CNC'){
					type = 'Click & Collect';
				}

				htmlList += '<div class="item">'+
							'<div class="con">'+
							'<div class="time-state">'+
							'<span class="time" data-id="'+result[i].bj_order_id+'" data-time="'+result[i].bs_create_time+'">'+result[i].bs_create_time+'</span>'+
							'<span class="state">'+result[i].bs_status+'</span>'+
							'</div>'+
							'<div class="order-info">'+
							'<div>Order no. <span>'+result[i].bs_order_no+'</span></div>'+
							'<div>Type<span>'+type+'</span></div>'+
							'<div>Amount <span>$'+result[i].bj_total_amount+'</span></div>'+
							'</div>'+
							'</div>'+
							'<p><a class="mui-btn">View Details</a></p>'+
							'</div>';
			}
			$('.listBox').html(htmlList);
			detail()
		}else {
			$('.listBox').html(no_result);
		}
	})
}

function detail(){
	$('.item').each(function(){
		var $this = $(this).find('.mui-btn');
		var id =$(this).find('.time').data('id');
		var createTime =$(this).find('.time').data('time');
		$this.on('tap',function(){
			sessionStorage.setItem("account_order_id",id);
			sessionStorage.setItem("createTime",createTime);
			window.location.href = MPJ.base+'/pages/account/order/detail.jsp';
		})
	})
}


/*
$('.listBox .item a.mui-btn').on('tap',function(){

	window.location.href = MPJ.base+'/pages/account/order/detail.jsp';
})
*/
